package com.rongc.client.freight.business.supply.view.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.rongc.client.core.utils.ActivityUtils;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseFragment;
import com.rongc.client.freight.base.view.activity.MapGdActivity;
import com.rongc.client.freight.business.carrier.model.ConveyanceBean;
import com.rongc.client.freight.business.supply.model.SupplyBean;

import butterknife.Bind;

/**
 * Created by ccqx on 2017/8/9.
 */

public class AddressFragment extends BaseFragment {

    @Bind(R.id.tv_departure)
    TextView mTvDeparture;
    @Bind(R.id.tv_destination)
    TextView mTvDestination;
    @Bind(R.id.tv_departure_tip)
    TextView mTvDepartureTip;
    @Bind(R.id.tv_destination_tip)
    TextView mTvDestinationTip;

    @Bind(R.id.lyt_departure)
    View mDeparture;
    @Bind(R.id.lyt_destination)
    View mDestination;


    public void setData(ConveyanceBean conveyanceBean){
        if(conveyanceBean !=null) {
            mTvDeparture.setText(conveyanceBean.getStartPlace());
//            mTvDepartureTip.setText(conveyanceBean.getStart_ssq());
            mTvDestination.setText(conveyanceBean.getEndPlace());
//            mTvDestinationTip.setText(conveyanceBean.getDistance());
            mDeparture.setTag(R.id.lng,conveyanceBean.getStartLon());
            mDeparture.setTag(R.id.lat,conveyanceBean.getStartLat());
            mDeparture.setTag(R.id.title,conveyanceBean.getStart_ssq());

            mDestination.setTag(R.id.lng,conveyanceBean.getEndLon());
            mDestination.setTag(R.id.lat,conveyanceBean.getEndLat());
            mDestination.setTag(R.id.title,conveyanceBean.getEnd_ssq());
        }
    }

    public void setData(SupplyBean supplyBean){
        if(supplyBean !=null) {
            mTvDeparture.setText(supplyBean.getStartPlace());
//            mTvDepartureTip.setText(supplyBean.getDistance());
            mTvDestination.setText(supplyBean.getEndPlace());
            if(StringUtils.isNotEmpty(supplyBean.getDistance()))
            mTvDestinationTip.setText(String.format(getActivity().getResources().getString(R.string.address_distance),
                    supplyBean.getDistance()));

            mDeparture.setTag(R.id.lng,supplyBean.getStartLon());
            mDeparture.setTag(R.id.lat,supplyBean.getStartLat());
            mDeparture.setTag(R.id.title,supplyBean.getStart_ssq());

            mDestination.setTag(R.id.lng,supplyBean.getEndLon());
            mDestination.setTag(R.id.lat,supplyBean.getEndLat());
            mDestination.setTag(R.id.title,supplyBean.getEnd_ssq());
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.include_address;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        mDeparture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("lng", (String) v.getTag(R.id.lng));
                bundle.putString("lat", (String) v.getTag(R.id.lat));
                bundle.putString("title", (String) v.getTag(R.id.title));
                ActivityUtils.startActivity(getActivity(),MapGdActivity.class,bundle);
            }
        });
        mDestination.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("lng", (String) v.getTag(R.id.lng));
                bundle.putString("lat", (String) v.getTag(R.id.lat));
                bundle.putString("title", (String) v.getTag(R.id.title));
                ActivityUtils.startActivity(getActivity(),MapGdActivity.class,bundle);
            }
        });
    }
}
